package home;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;

public class Sorting_RY {

    public void CreateFile() {
        try {
            String data="gshndgfvhsd 10 sdkhfjsdkf\nhjhhhereeh 1 hhhdhgf\noiyuuiyhoiuyui 90 kugkjygjkygy\n";
            File file = new File("C:\\Selenium\\first_test_RY\\filename.txt");


            // if file doesnt exists, then create it
            if (!file.exists()) {
                file.createNewFile();
            }

            FileWriter fw = new FileWriter(file.getAbsoluteFile());
            BufferedWriter bw = new BufferedWriter(fw);
            bw.write(data);
            bw.close();

        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public int[] EraseChar() throws IOException {
        String[] listOfRows = read();
        System.out.println("Lines ->" + Arrays.toString(listOfRows));
        int[] a = new int[3];
        System.out.println("Regex process ->" +listOfRows[0]);
        String[] array = (listOfRows[0].replaceAll("\\D+", " ").trim()).split(" ");
        for (int k = 0; k < 3; k++) {
            System.out.println("Some after regex ->"
                    + Arrays.toString(array));

            a[k] = Integer.valueOf(array[k]);

        }
        return a;
    }

    public String[] read() throws IOException {
        String token1 = "";
        Scanner inFile1;
        inFile1 = new Scanner(new File(
                "C:\\Selenium\\first_test_RY\\filename.txt"))
                .useDelimiter(",\\t*");
        List<String> temps = new LinkedList<String>();
        while (inFile1.hasNext()) {
            token1 = inFile1.next();
            temps.add(token1);
        }
        inFile1.close();

        String[] tempsArray = temps.toArray(new String[0]);
        return tempsArray;
    }

    public void DeleteFile() {
        try {
            File file = new File(
                    "C:\\Selenium\\first_test_RY\\filename.txt");

            file.delete();
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}
